package cn.java.exercises;

import cn.java.basic.JStudent;

class JTriangle
{
    public double edge_a;
    public double edge_b;
    public double edge_c;

    public JTriangle(double edge_a,double edge_b,double edge_c)
    {
        //注意未做有效性检查,应保证任意两边之和大于第三边
        this.edge_a=edge_a;
        this.edge_b=edge_b;
        this.edge_c=edge_c;
    }

    public double calcCircle()
    {
        double circle=edge_a+edge_b+edge_c;
        System.out.println(String.format("三角形周长=%.2f",circle));
        return circle;
    }

    public double calcArea()
    {
        double p=(edge_a+edge_b+edge_c)/2;
        double s=Math.sqrt(p*(p-edge_a)*(p-edge_b)*(p-edge_c));
        System.out.println(String.format("三角形面积=%.2f",s));
        return s;
    }

}

class JSquare
{
    public double edge;

    public JSquare(double edge)
    {
        this.edge=edge;
    }

    public double calcCircle()
    {
        System.out.println(String.format("正方形周长=%.2f",edge*4));
        return edge*4;
    }

    public double calcArea()
    {
        System.out.println(String.format("正方形面积=%.2f",edge*edge));
        return edge*edge;
    }
}

class JCircle
{
    public double radius;

    public JCircle(double radius)
    {
        this.radius=radius;
    }

    public double calcCircle()
    {
        System.out.println(String.format("圆形周长=%.2f",2*Math.PI*radius));
        return 2*Math.PI*radius;
    }

    public double calcArea()
    {
        System.out.println(String.format("圆形面积=%.2f",Math.PI*radius*radius));
        return Math.PI*radius*radius;
    }

}

class JRPentagon
{
    public double edge;

    public JRPentagon(double edge)
    {
        this.edge=edge;
    }

    public double calcCircle()
    {
        System.out.println(String.format("正五边形周长=%.2f",edge*5));
        return edge*5;
    }

    public double calcArea()
    {
        double r=0.5*edge/Math.tan(Math.PI/5);
        double s=0.5*r*edge*5;
        System.out.println(String.format("正五边形面积=%.2f",s));
        return s;
    }


}

public class ShapeDemo
{
    public static void main(String[] args)
    {
        JTriangle triangle=new JTriangle(3,4,5);

        triangle.calcCircle();
        triangle.calcArea();

        JSquare square=new JSquare(5);
        square.calcCircle();
        square.calcArea();

        JCircle circle=new JCircle(5);
        circle.calcCircle();
        circle.calcArea();

        JRPentagon pentagon=new JRPentagon(5);
        pentagon.calcCircle();
        pentagon.calcArea();


    }
}
